<template>
    <view class="page-invitation-list">
		<view class="p-4" v-if="longList.list.length == 0">
            <u-empty text="暂无内容" mode="list"></u-empty>
        </view> 
		<u-gap height="30"></u-gap>
		<view class="list">
			<view class="fly-panel" v-for="(item,index) in longList.list" :key="index">
				<view class="hd"><view class="title">{{ proxy.$util.setName(item.type, optionData.typeList) }}</view></view>
				<view class="bd">
					<view>
						<fly-info label="订单号" :value="item.billId"></fly-info>
						<fly-info label="活动名称" v-if="item.type == 'activities'" :value="proxy.$util.setName(item.relationshipId, optionData.cardList)"></fly-info>
						<fly-info label="卡类型" v-else :value="proxy.$util.setName(item.relationshipId, optionData.cardList)"></fly-info>
						<fly-info label="金额" :value="item.amount + '元'"></fly-info>
						<fly-info label="状态" :value="proxy.$util.setName(item.status, optionData.billStatus)"></fly-info> 
						<fly-info label="支付时间" :value="item.payTime"></fly-info>
					</view>					
		 		</view>
				<view class="ft" v-if="item.status == '1' && checkRefund(item)">
					<u-button class="btn-red" size="mini" @click="handleRefund(item)">退款</u-button>
				</view>
			</view>
		</view>
    </view>
</template>
<script setup lang="ts">
import dayjs from 'dayjs';
import FlyInfo from '@/components/FlyInfo';
import {onShow, onPullDownRefresh, onReachBottom, onShareAppMessage } from '@dcloudio/uni-app';
import { useLonglist } from '@/static/fn/longList';
const initObj = {
	listApi:'/admin/bill/xcxPage',
}
let { searchForm, longList, getList} = useLonglist(initObj);
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
import { useAppStore } from '@/stores/app'
import { useOptionData } from '@/stores/optionData';
let appStore = useAppStore();
const optionDataStore = useOptionData();
let optionData = reactive({});
const getInitData = async () => {
    optionData.durationType = await optionDataStore.getDictList('duration_type');
    optionData.billStatus = await optionDataStore.getDictList('bill_status');
	let cardList = await proxy.$http('get', '/admin/membershipCards/page', {current:1, size:30});
	optionData.cardList = cardList.records.map(item => {
		item.id = item.cardId;
		item.name = item.cardName;
		return item;
	});
	optionData.typeList = [{id: 'xu', name: '会员续费'},{id: 'new', name: '会员注册'},{id: 'activity', name: '活动报名'}]
};
const handleRefund = (item) => {
	uni.showModal({
		title: '确定要退款吗？',
		editable: true,
		placeholderText: '请输入备注',
		success: res => {
			if(res.confirm){
				let params = {
					billId: item.billId,
					type: item.type,
					remark: res.content
				}
				proxy.$http('post', '/admin/refundApply', params, (data,msg) => {
					uni.showToast({title: '提交成功', icon: 'none'});
					getList('refresh');
				})
			}
		}
	})
};
const checkRefund = (item) => {
	let day = dayjs(item.payTime).diff(dayjs(), 'day');
	console.log(day);
	if(day > 7){
		return false;
	}else{
		return true;
	}
}

onPullDownRefresh(() => {
	getList('refresh');
	setTimeout( () => {
		uni.stopPullDownRefresh();
	}, 1000);
});
onReachBottom(() =>{
	getList();
});
onShow(() => {
	// searchForm.status = '1';
	getInitData();
	getList('refresh');
	// longList.list = [1,2,3]
})
</script>